package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysCodeRules;
import com.ruoyi.project.system.service.ISysCodeRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 自动编码规则Controller
 * 
 * @author woniu
 * @date 2020-07-01
 */
@RestController
@RequestMapping("/system/codeRules")
public class SysCodeRulesController extends BaseController
{
    @Autowired
    private ISysCodeRulesService sysCodeRulesService;

    /**
     * 查询自动编码规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:codeRules:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCodeRules sysCodeRules)
    {
        startPage();
        List<SysCodeRules> list = sysCodeRulesService.selectSysCodeRulesList(sysCodeRules);
        return getDataTable(list);
    }

    /**
     * 导出自动编码规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:codeRules:export')")
    @Log(title = "自动编码规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysCodeRules sysCodeRules)
    {
        List<SysCodeRules> list = sysCodeRulesService.selectSysCodeRulesList(sysCodeRules);
        ExcelUtil<SysCodeRules> util = new ExcelUtil<SysCodeRules>(SysCodeRules.class);
        return util.exportExcel(list, "codeRules");
    }

    /**
     * 获取自动编码规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:codeRules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysCodeRulesService.selectSysCodeRulesById(id));
    }

    /**
     * 新增自动编码规则
     */
    @PreAuthorize("@ss.hasPermi('system:codeRules:add')")
    @Log(title = "自动编码规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCodeRules sysCodeRules)
    {
        return toAjax(sysCodeRulesService.insertSysCodeRules(sysCodeRules));
    }

    /**
     * 修改自动编码规则
     */
    @PreAuthorize("@ss.hasPermi('system:codeRules:edit')")
    @Log(title = "自动编码规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCodeRules sysCodeRules)
    {
        return toAjax(sysCodeRulesService.updateSysCodeRules(sysCodeRules));
    }

    /**
     * 删除自动编码规则
     */
    @PreAuthorize("@ss.hasPermi('system:codeRules:remove')")
    @Log(title = "自动编码规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCodeRulesService.deleteSysCodeRulesByIds(ids));
    }


}
